﻿using System;
using System.Collections.Generic;

using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace SceneEngine
{
    public class ModelInformation
    {
        private List<string> originalTexturePaths = new List<string>();
        private List<string> relativeTexturePaths = new List<string>();

        private List<Vector3> vertices;

        private BoundingSphere sphere;

        public List<string> OriginalTexturePaths
        {
            get { return originalTexturePaths; }
            set { originalTexturePaths = value; }
        }
        public List<string> RelativeTexturePaths
        {
            get { return relativeTexturePaths; }
            set { relativeTexturePaths = value; }
        }

        public List<Vector3> Vertices
        {
            get { return vertices; }
            set 
            { 
                vertices = value;
                sphere = BoundingSphere.CreateFromPoints(vertices);
            }
        }

        public BoundingSphere BoundingSphere
        {
            get { return sphere; }
        }
    }

    public class ModelInformationReader : ContentTypeReader<ModelInformation>
    {
        protected override ModelInformation Read(
            ContentReader input, ModelInformation existingInstance)
        {
            if (existingInstance != null)
                return existingInstance;

            ModelInformation modelInfo = new ModelInformation();

            List<string> originalTexturePaths = new List<string>();
            List<string> relativeTexturePaths = new List<string>();

            int textureCount = input.ReadInt32();

            for (int i = 0; i < textureCount; i++)
            {
                originalTexturePaths.Add(input.ReadString());
                relativeTexturePaths.Add(input.ReadString());
            }

            List<Vector3> vertices = new List<Vector3>();

            int vertexCount = input.ReadInt32();

            for (int i = 0; i < vertexCount; i++)
            {
                vertices.Add(input.ReadVector3());
            }

            modelInfo.OriginalTexturePaths = originalTexturePaths;
            modelInfo.RelativeTexturePaths = relativeTexturePaths;

            modelInfo.Vertices = vertices;

            return modelInfo;
        }
    }
}
